package com.imooc.coupon.gateway.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletRequest;

/**
 * Token过滤器
 * Created By TINY
 * Create Time 2020/2/9 - 1:47
 **/
@Slf4j
//@Component
public class TokenFilter extends AbstractPreZuulFilter {
    @Override
    protected Object cRun() {
        HttpServletRequest request = context.getRequest();

        log.info(String.format("%s request -> %s",
                request.getMethod(), request.getRequestURL()));

        Object token = request.getParameter("token");
        if (null == token) {
            log.error("error: token is empty!");
            fail(401, "error: token is empty!");
        }
        return success();
    }

    @Override
    public int filterOrder() { return 1; }
}
